// 一般客户端使用历史模式 ， 后台管理系统使用 hash 模式
import Login from "@/views/Login";
// import Home from "@/views/Home";
// import Fast from "@/views/Fast";
// import Mine from "@/views/Mine";
// import Select from "@/views/Select";
// import Practice from "@/views/Practice";
// import Subjects from "@/views/Subjects";
import App from "@/views/App";
import {
  createBrowserRouter as createRouter,
  redirect,
} from "react-router-dom";
import Err404 from "@/components/Err404";
import { lazy } from "react";

// react的路由的懒加载，需要配合一个 lazy 的函数实现
const Home = lazy(() => import("../views/Home"));
const Fast = lazy(() => import("../views/Fast"));
const Mine = lazy(() => import("../views/Mine"));
const Select = lazy(() => import("../views/Select"));
const Practice = lazy(() => import("../views/Practice"));
const Subjects = lazy(() => import("../views/Subjects"));

// 7个页面  (登录/注册)  首页 我的  快速刷题  选题  做题  切换学科
const router = createRouter([
  {
    path: "/login",
    element: <Login />,
  },
  {
    path: "/",
    element: <App />,
    children: [
      // 所有需要登录后垢能访问的页面
      {
        path: "home",
        element: <Home />,
      },
      {
        path: "fast",
        element: <Fast />,
      },
      {
        path: "mine",
        element: <Mine />,
      },
      {
        path: "sel/:actionCode",
        element: <Select />,
      },
      {
        path: "pra",
        element: <Practice />,
      },
      {
        path: "sub",
        element: <Subjects />,
      },
    ],
  },
  {
    path: "*",
    element: <Err404 />,
  },
]);

export default router;
